package com.example.mobile2032021606168xmy05222;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private ImageView ivMainPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        ivMainPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent,1);
            }


           protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
                MainActivity.super.onActivityResult(requestCode,requestCode,data);
                if (resultCode==RESULT_OK && requestCode==1){
                    Bundle bundle=data.getExtras();
                    Bitmap bitmap=(Bitmap)bundle.get("data");
                    ivMainPhone.setImageBitmap(bitmap);
                }
            }
        });
    }

    private void initView() {
        ivMainPhone = (ImageView) findViewById(R.id.iv_main_phone);
    }
}